package com.coolrui.domain.prometheus;

import io.micrometer.core.instrument.Counter;
import io.micrometer.core.instrument.MeterRegistry;
import org.springframework.stereotype.Component;

@Component
public class RequestMetricsService {

    private static final String METRIC_NAME = "custom.order.requests.total";
    private final MeterRegistry registry;

    public RequestMetricsService(MeterRegistry registry) {
        this.registry = registry;
    }

    /**
     * 记录请求，支持通过 uri 和 service 区分不同的接口和服务
     * @param uri     接口URI，比如 UserOrderService.createOrder
     * @param service 服务名称，比如 UserOrderService
     */
    public void recordRequest(String uri, String service) {
        Counter counter = registry.counter(
                METRIC_NAME,        // 指标名称
                "uri", uri,  // 接口URI
                "service", service  // 服务名称
        );
        counter.increment();
    }
}
